<?php
/**
 * Created by ThinkPHP5.0.22.
 * User: 小涛.
 * Date: 2018/12/27.
 * Time: 22:36.
 */

namespace app\admin\model;

use think\Model;
use think\Request;


/**
 * Class News 资讯列表
 * @package app\admin\model
 */
class News extends Model
{
    //新闻类型与新闻咨询中心的对应关系
    public function NewsByType(){
        return $this->belongsTo("NewsType","news_type","id");
    }

    //图片与新闻咨询中心图片logo的对应关系
    public function UploadLogo(){
        return $this -> belongsTo("Upload","logo","id");
    }

    //列表
    public static function listNews($member_id = 0,$listRow = 10){
        $list = self::with("NewsByType,UploadLogo");
        if($member_id == 0){
            $list = $list -> where(["member_id" => 0]);
        } else {
            $list = $list -> where("member_id != 0");
        }
        return $list -> order("sort asc")
            -> paginate($listRow, false, [
                "query" => Request::instance() -> param()
            ]);
    }
}